package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.model.Domainmodelattr;
import sjtu.ist.warehouse4ws.model.Domainmodelstate;
import sjtu.ist.warehouse4ws.service.DomainModelAttributeService;
import sjtu.ist.warehouse4ws.service.DomainModelService;
import sjtu.ist.warehouse4ws.service.DomainModelStateService;
import sjtu.ist.warehouse4ws.service.OplogService;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class ShowDomainModelAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3559225084848274205L;
	private DomainModelAttributeService domainModelAttributeService;
	private DomainModelStateService domainModelStateService;
	private DomainModelService domainModelService; 
	private OplogService oplogService;
	private List<Domainmodelattr> attributeList = new ArrayList<Domainmodelattr> ();
    private List<Domainmodelstate> stateList=new ArrayList<Domainmodelstate>();
    private String domainId;
  

	public String getDomainId() {
		return domainId;
	}
	public void setDomainId(String domainId) {
		this.domainId = domainId;
	}
	public void setDomainModelAttributeService(
		DomainModelAttributeService domainModelAttributeService) {
		this.domainModelAttributeService = domainModelAttributeService;
	}
	public void setDomainModelStateService(
		DomainModelStateService domainModelStateService) {
		this.domainModelStateService = domainModelStateService;
	}
	public void setDomainModelService(DomainModelService domainModelService) {
		this.domainModelService = domainModelService;
	}
	public void setOplogService(OplogService oplogService) {
		this.oplogService = oplogService;
	}
	//DomainModel
	public String showDomainModelAttribute(){
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.domainId=request.getParameter("cid");
		this.attributeList=domainModelAttributeService.getDomainModelAttributeList(getDomainId());
		
		//插入日志记录/////////////////////////////////////////////////////
		Domainmodel dm=domainModelService.getDomainModel(domainId);
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		String user_id = session.get("user_id").toString();
		oplogService.recordLog(user_id, dm.getFileId(), "查看对象模型", "readop");
		//////////////////////////////////////////////////////////////////////
		
		return SUCCESS;
		}
	public String showDomainModelState(){
		HttpServletRequest request = ServletActionContext.getRequest ();
		this.domainId=request.getParameter("cid");
		this.stateList=domainModelStateService.getDomainModelStateList(getDomainId());
		return SUCCESS;
		}
	@JSON(name = "totalAttribute")	
	public int getTotalAttribute() {
		return this.attributeList.size();
	}
    
	@JSON(name ="Domainmodelattr")	
	public List<Domainmodelattr> getAttributeList() {
		return this.attributeList;
	}
	@JSON(name = "totalState")	
	public int getTotalState() {
		return this.stateList.size();
	}
    
	@JSON(name ="Domainmodelstate")	
	public List<Domainmodelstate> getStateList() {
		return this.stateList;
	}
	
	
}
